package com.tjsinfo.tjsoa.workplan.action;

import java.util.Date;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.system.vo.User;
import com.tjsinfo.tjsoa.workplan.bo.IWorkPlanMainBo;
import com.tjsinfo.tjsoa.workplan.vo.WorkPlanMain;

/**
 * 工作计划月历模式
 * @author wangxiaowei
 *
 */

public class WorkPlanMonthModleAction extends Action{
	 protected IWorkPlanMainBo workPlanMainBo;
	
	/**
	 * @return the workPlanMainBo
	 */
	public IWorkPlanMainBo getWorkPlanMainBo() {
		return workPlanMainBo;
	}

	/**
	 * @param workPlanMainBo the workPlanMainBo to set
	 */
	public void setWorkPlanMainBo(IWorkPlanMainBo workPlanMainBo) {
		this.workPlanMainBo = workPlanMainBo;
	}

	/* (non-Javadoc)
	 * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		try {
			Date date = new Date();
			Map<Integer, WorkPlanMain> map =	selectWorkPlanYear("M", date, request);
			return forword(mapping, request, date, map);
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return mapping.findForward("error");
		}
	}
	/**
	 * 转发方法
	 * @param mapping
	 * @param request
	 * @param date
	 * @param map
	 * @return
	 */
	protected ActionForward forword(ActionMapping mapping,
			HttpServletRequest request, Date date, Map<Integer, WorkPlanMain> map) {
		request.setAttribute("map", map);
		request.setAttribute("yueli", date);
		return mapping.findForward("ok");
	}
	/**
	 * 对于每个一年的工作计划进行查询
	 * @return map
	 */
	protected Map<Integer, WorkPlanMain> selectWorkPlanYear(String type, Date date,HttpServletRequest request) {
		HttpSession session = request.getSession();
		User user = (User)session.getAttribute("user");
		return   workPlanMainBo.selectWorkPlanTypeAndYearMAPNumber(type, date.getYear()+1900, user.getUser_id());
	}
	
}
